package crawler.cnki.config;

import crawler.cnki.selenium.SeleniumDownloader;
import crawler.cnki.selenium.WebDriverPool;
import crawler.cnki.task.DataAction;
import crawler.cnki.task.DataPipeline;
import crawler.cnki.task.PoolUtil;
import crawler.cnki.task.ProjectProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.scheduler.RedisScheduler;

@Configuration
public class SpiderConfig {
    @Autowired
    JedisPool jedisPool;
    @Autowired
    DataPipeline dataPipeline;

    @Bean
    public Spider getspider(){
        return Spider.create(new ProjectProcessor())
                .setUUID("Researcher")
                .setScheduler(new RedisScheduler(jedisPool))
                .setDownloader(new SeleniumDownloader(0, PoolUtil.getWebDriverPool(), new DataAction()))
                .addPipeline(dataPipeline)
                .thread(1);
    }
}
